package com.zsd.android.opengldemo.presenter;

import com.zsd.android.opengldemo.model.BaseModel;
import com.zsd.android.opengldemo.view.IBaseView;

import java.lang.ref.WeakReference;

public abstract class BasePresenter<V extends IBaseView, M extends BaseModel> {

    protected M mModel;
    protected WeakReference<V> mReference;

    public BasePresenter(V mView) {
        mReference = new WeakReference<>(mView);
        mModel = initModel();
    }

    public V getView() {
        if (mReference == null) {
            return null;
        }
        return mReference.get();
    }

    public void detach() {
        if (mReference != null) {
            mReference.clear();
            mReference = null;
            System.gc();
        }
    }

    public abstract M initModel();
}
